<?
    require_once("./DButil.php");
    $id = $_REQUEST["id"];
    $name = $_REQUEST["name"];
    $begin=$_REQUEST["begin"];
    $end=$_REQUEST["end"];
    // if($id){
    //     $sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_id = '{$id}'";
    //     $arr = query($sql);
    //     $p = $arr[0];
    //     echo json_encode($p);
    // }
    // if($name){
    //     $sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_name = '{$name}' ";
    //     $arr = query($sql);
    //     $p = $arr[0];
    //     echo json_encode($p);
    // }
    // if($begin && $end){
    //     $sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_price between '{$begin}' and '{$end}' ";
    //     $arr = query($sql);
    //     $p = $arr[0];
    //     echo json_encode($p);
    // }
    // if($id &&  $name){
    //     $sql1 = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_id = '{$id}' and p_name = '{$name}' ";
    //     $arr1 = query($sql1);
    //     $p1 = $arr1[0];
    //     echo json_encode($p1);
    // }


    if($id &&  $name && $begin && $end){
        $sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_id = '{$id}' and p_name like '%{$name}%' and p_price between '{$begin}' and '{$end}' ";
    }else if($id && $begin && $end){
        $sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_id = '{$id}' and p_price between '{$begin}' and '{$end}' ";
    }else if($name  && $begin && $end){
        $sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where  p_name like '%{$name}%' and p_price between '{$begin}' and '{$end}' ";
    }else if($id && $name){
        $sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_id = '{$id}' and p_name like '%{$name}%' ";     
    }
    else if($id){
        $sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_id = '{$id}'"; 
    }else if($name){
        $sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_name like '%{$name}%' ";
    }else if($begin && $end){
        $sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_price between '{$begin}' and '{$end}' ";
    }
    $arr = query($sql);
    $p = $arr[0];
    echo json_encode($p);

?>